package com.common.projectcommonframe;

import android.content.Context;
import android.content.Intent;

import com.common.projectcommonframe.ui.test.TestActivity;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.CountDownLatch;

import androidx.test.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

//    @Rule
//    public final ActivityTestRule activityTestRule = new ActivityTestRule<>(TestActivity.class, true, false);

    @Test
    public void useAppContext() throws InterruptedException {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();
        //通过Intent跳转
//        Intent intent = new Intent(appContext,AnotherActivity.class);
//        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        appContext.startActivity(intent);

        Intent intent = new Intent(appContext, TestActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        //通过AndroidTestRule跳转
        ActivityTestRule<TestActivity> activityTestRule = new ActivityTestRule<>(TestActivity.class, false, false);
        activityTestRule.launchActivity(null);

        //AndroidJUnit4快速启动一个activity，并且不自动退出  使用下面代码
        CountDownLatch countdown = new CountDownLatch(1);
        countdown.await();
    }
}
